<template>
  <p-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <p-spin :spinning="confirmLoading">
      <p-form :form="form">
        <p-row>
		  <p-col  :span="12">
			<p-form-item label="点检单号" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'spotCheckodd', validatorRules.spotCheckodd]" placeholder="请输入点检单号"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="设备编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'deviceno', validatorRules.deviceno]" placeholder="请输入设备编码"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="设备名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'devicename', validatorRules.devicename]" placeholder="请输入设备名称"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="点检部位" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'checkParts', validatorRules.checkParts]" placeholder="请输入点检部位"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="点检标准" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'checkstno', validatorRules.checkstno]" placeholder="请输入点检标准"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="上限值" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'upValue', validatorRules.upValue]" placeholder="请输入上限值"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="下限值" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'belowValue', validatorRules.belowValue]" placeholder="请输入下限值"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="点检方法" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'checkidea', validatorRules.checkidea]" placeholder="请输入点检方法"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="点检结果" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'checkresult', validatorRules.checkresult]" placeholder="请输入点检结果"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="结果判定" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input-number   v-decorator="[ 'decide', validatorRules.decide]" placeholder="请输入结果判定" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="点检人员" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-select-user-by-dep v-decorator="['personnel', validatorRules.personnel]" :trigger-change="true"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="点检时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-date    placeholder="请选择点检时间" v-decorator="[ 'theTallyTime', validatorRules.theTallyTime]" :trigger-change="true" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="12">
			<p-form-item label="id外建" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'mesMfOpenlistId', validatorRules.mesMfOpenlistId]" placeholder="请输入id外建"></p-input>
			</p-form-item>
		  </p-col>
        </p-row>


      </p-form>
    </p-spin>
  </p-modal>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import { SubmitOnchangMixin } from '@/mixins/SubmitOnchangMixin'
  import pick from 'lodash.pick'
  import JDate from '@/components/jeecg/JDate'
  import JSelectUserByDep from '@/components/jeecgbiz/JSelectUserByDep'

  export default {
    name: "MesMfLineTheTallyModal",
	mixins: [SubmitOnchangMixin],
    components: {
      JDate,
      JSelectUserByDep,
    },
    props:{
      mainId:{
        type:String,
        required:false,
        default:''
      }
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title: '操作',
        width: 800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules:{
        spotCheckodd: {},
        deviceno: {},
        devicename: {},
        checkParts: {},
        checkstno: {},
        upValue: {},
        belowValue: {},
        checkidea: {},
        checkresult: {},
        decide: {},
        personnel: {},
        theTallyTime: {},
        mesMfOpenlistId: {},
        },
        url: {
          add: '/mes-manufacture/auto/mesMfOpenLineInspectionList/addMesMfLineTheTally',
          edit: '/mes-manufacture/auto/mesMfOpenLineInspectionList/editMesMfLineTheTally',
        }

      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'createBy','createTime','updateBy','updateTime','remark','timestamp','companyId','factoryId','clientId','substituteId','flag','mnum','spotcheckTemplate','istates','spotCheckodd','deviceid','deviceno','devicename','checkParts','checkstno','upValue','belowValue','checkidea','checkresult','decide','theTallyOrder','personnel','theTallyTime','mesMfOpenlistId'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
		handleOk () {
			const that = this;
			// 触发表单验证
			this.form.validateFields((err, values) => {
			  if (!err) {
				  that.confirmLoading = true;
				  let httpurl = '';
				  let method = '';
				  let formData = Object.assign(this.model, values);
				  this.formData = Object.assign(this.model, values);
                  formData['mesMfOpenlistId'] = this.mainId
                  this.formData['mesMfOpenlistId'] = this.mainId
				  //新增触发
				  if(!this.model.id){
					httpurl+=this.url.add;
					method = 'post';
					if(this.EnhanceJS.afterAdd){
					  //新增之前
					  let Obj = eval(this.EnhanceJS.afterAdd)
					  new Obj(this)
					}else{
					  console.log("表单提交数据",formData)
					  that.modalFrom(httpurl,formData,method)
					}
				  }else{
					//编辑触发
					httpurl+=this.url.edit;
					method = 'put';
					if(this.EnhanceJS.afterEdit){
					 //编辑之前
					  let Obj = eval(this.EnhanceJS.afterEdit)
					  new Obj(this)
					}else{
					  console.log("表单提交数据",formData)
					  that.modalFrom(httpurl,formData,method)
					}
				  }
			  }

			})
		},
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'createBy','createTime','updateBy','updateTime','remark','timestamp','companyId','factoryId','clientId','substituteId','flag','mnum','spotcheckTemplate','istates','spotCheckodd','deviceid','deviceno','devicename','checkParts','checkstno','upValue','belowValue','checkidea','checkresult','decide','theTallyOrder','personnel','theTallyTime','mesMfOpenlistId'))
      },


    }
  }
</script>
